package org.groupg.practice.tablesaw;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import tech.tablesaw.api.ColumnType;
import tech.tablesaw.api.StringColumn;
import tech.tablesaw.api.Table;
import tech.tablesaw.io.csv.CsvReadOptions;
import tech.tablesaw.selection.Selection;

import java.io.File;

public class BasicOperationsExample {
    public static void main(String[] args) {

        TimeInterval timeInterval = new TimeInterval();
        timeInterval.start();

        // 假设你已经有一个 Table 对象
        File file = new File("F:\\DATA\\demo\\sys_user50w.csv");
        CsvReadOptions csvReadOptions = CsvReadOptions.builder(file).columnTypes(new ColumnType[]{ColumnType.STRING, ColumnType.STRING, ColumnType.STRING, ColumnType.STRING, ColumnType.STRING, ColumnType.STRING, ColumnType.STRING, ColumnType.STRING, ColumnType.STRING, ColumnType.STRING}).build();
        Table table = Table.read().csv(csvReadOptions);

        // 选择特定列
        StringColumn orgcode = table.stringColumn("orgcode");
        StringColumn cnname = table.stringColumn("CNNAME");


        // 选择特定行
        Selection selection = cnname.equalsIgnoreCase("李x");
        Selection selection1 = selection.or(cnname.containsString("王x").and(orgcode.containsString("90")));

//        Table filteredTable = table.where(selection);
//        // 打印选择的行
//        System.out.println(filteredTable.shape());
//        System.out.println(filteredTable);

        Table filteredTable1 = table.where(selection1);
        // 打印选择的行
        System.out.println(filteredTable1.shape());
//        System.out.println(filteredTable1);

        //  3秒506毫秒      50w数据
        //  23秒453毫秒     500w数据
        System.out.println("耗时："+DateUtil.formatBetween(timeInterval.interval()));
    }
}